<?php 
session_start();
$lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
	include "../../value/value_en.php";
} else if($lang == "VN") {
	include "../../value/value_vn.php";
}
else {
	include "../../value/value_kr.php";
}
include '../../generallibraries/funcs.php';
include '../../operations/connection.php';	

$list["ac_customer.Email"]="ASC";
$list["ac_customer.CustomerName"]="ASC";
$list["ac_customer.Address"]="ASC";
$list["ac_customer.Phone"]="ASC";
$list["ac_customer.Fax"]="ASC";
$list["ac_customer.CreatedDate"]="DESC";
$str="ac_customer.CreatedDate";
$_SESSION['accsortn']=$str;
$_SESSION['accsort']=$list;
$page=1;
$rows_per_page = $_SESSION['accrows_page'] ;
$page_start = ( $page - 1 ) * $rows_per_page; 
$page_end = $page * $rows_per_page;
$co=0;
$hamsort=" ORDER BY ".$str." ".$list[$str]."";
$sqlCustomer = generalFunctions::listCustomer("ac_customer.CustomerID, ac_customer.CustomerName, ac_customer.Address, ac_customer.Phone, ac_customer.Fax,ac_customer.Email",$hamsort);
$mangCustomer=mysql_query($sqlCustomer);
$number_of_page = ceil ( mysql_num_rows( $mangCustomer ) / $rows_per_page ); 
$_POST['searchname']="";
$_SESSION['checksoluong']=mysql_num_rows( $mangCustomer );
?>
<input type="hidden" name="content" value="accountant-setup-customer-content" />
			<div style="margin: 10px 0px 5px 5px;">
				<table>
					<tr>
						<td style="vertical-align:middle"><?php echo $l_customername;?></td>
						<td id="txtsearch"><input onkeyup="changeSearch(this.value);" style="width:250px; autocomplete:off; " type="text" name="searchname" class="in_testfield" id="searchname"  value="<?=$_POST['searchname']?>"/></td>
						<td><input onclick="resetcustomer();" type="button" value="Reset" class="btnupbg btnupload" /></td>
					</tr>
				</table>
			</div>
			<div id="viewlistcustomer" style="width:100%">
			<table class="cssTable" width="100%">
				<thead>
					<tr>
						<th scope="col"></th>
						<th scope="col"><a onclick="sort(<?=$page?>,'ac_customer.CustomerName',1);" ><?php echo $l_customername;?></a></th>
						<th scope="col"><a onclick="sort(<?=$page?>,'ac_customer.Address',1);" ><?php echo $l_address;?></a></th>
						<th scope="col"><a onclick="sort(<?=$page?>,'ac_customer.Phone',1);" ><?php echo $l_phone;?></a></th>
						<th scope="col"><a onclick="sort(<?=$page?>,'ac_customer.Fax',1);" ><?php echo $l_Fax;?></a></th>
						<th scope="col"><a onclick="sort(<?=$page?>,'ac_customer.Email',1);" ><?php echo $l_email;?></a></th>
					</tr>
				</thead>
				<tbody>
					<?php 
						if(mysql_num_rows($mangCustomer)>0){
							$i=0;
							while($row = mysql_fetch_array($mangCustomer)){
								if ( $i >= $page_start ){
								?>
									<tr>
									<td><div style="text-align:center"><input onclick="checkonly(this.id,document.accsetupcus.list);" type="checkbox" name="list" id="<?php echo 'checkcus'.$i?>" value="<?=$row[CustomerID]?>"/></div></td>
									<td><?php echo $row[CustomerName];?></td>
									<td><?php echo $row[Address];?></td>
									<td><?php echo $row[Phone];?></td>
									<td><?php echo $row[Fax];?></td>
									<td><?php echo $row[Email];?></td>
									</tr>
								<?php 
								}
								$i++;
								if ($i >= $page_end){ 
									break; 
								}
							}								
						}
					?>
					<tr>
						<td colspan="6" class="bt_td_main">
							<span style="background:#fff; padding:1px; display: inline-block;">
														
								<?php if ( $number_of_page > 1 ) 
								{ 
									if ($page==1)
										$p=2;
									else if ($page==$number_of_page)
										$p=$number_of_page-1;
									else $p=$page;
									if($page!=1){?>
										<a onclick="sort(1,'<?=$str?>',0);" ><span class='button_next'><?php echo "<<<";?></span> </a>
										<a onclick="sort(<?=($page-1)?>,'<?=$str?>',0);" ><span class='button_next'><?php echo "<<";?></span> </a>
									<?php  }
									else{ 
										?>
										<span class='button_next'><?php echo "<<<";?></span>
										<span class='button_next'><?php echo "<<";?></span>
										<?php
									}
									for ( $i = $p-1; $i <= $p+1; $i++ ) {	
											if ($i<=$number_of_page && $i>0)
											
												if ($i==$page){
													echo "<span class='button_next'><b>".$i."</b></span>"; 
												}else{
												?>
													<a onclick="sort(<?=$i?>,'<?=$str?>',0);" ><span class="button_next">
													<?php 
													echo $i;
													?>
													</span> </a>
													<?php 
												}
											?>
										
									<?php 
											}
										
										if($page!=$number_of_page){ ?>
											<a onclick="sort(<?=($page+1)?>,'<?=$str?>',0);"><span class='button_next'><?php echo ">>";?></span> </a>
											<a onclick="sort(<?=($number_of_page)?>,'<?=$str?>',0);" ><span class='button_next'><?php echo ">>>";?></span> </a>
										<?php }
										else{
											echo "<span class='button_next'>>></span> ";
											echo "<span class='button_next'>>>></span> ";
										}
									}
								
									
									?>
																						
							</span>
						</td>
					</tr>
				</tbody>
			</table>
			</div>
			<?php mysql_close($connection);?>